package com.jiangnan.warehouse_management.controller;

import com.jiangnan.warehouse_management.common.Result;
import com.jiangnan.warehouse_management.dto.request.InventoryCheckRequest;
import com.jiangnan.warehouse_management.dto.response.InventoryQueryResponse;
import com.jiangnan.warehouse_management.dto.response.InventoryResponse;
import com.jiangnan.warehouse_management.dto.response.InventoryWarningListResponse;
import com.jiangnan.warehouse_management.dto.response.InventoryStatsResponse;
import com.jiangnan.warehouse_management.pojo.Inventory;
import com.jiangnan.warehouse_management.service.InventoryService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class InventoryController {

    private final InventoryService inventoryService;

    @GetMapping("/getInventory")
    public Result<InventoryQueryResponse> getInventory(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "itemId", required = false) Integer itemId,
            @RequestParam(value = "warehouseId", required = false) Integer warehouseId,
            @RequestParam(value = "lowStock", required = false) Boolean lowStock) {
        
        InventoryQueryResponse data = inventoryService.getInventoryList(
            page, pageSize, itemId, warehouseId, lowStock);
        return Result.success(data);
    }

    @GetMapping("/inventoryById/{id}")
    public Result<InventoryResponse> getInventoryById(@PathVariable Integer id) {
        InventoryResponse data = inventoryService.getInventoryById(id);
        return Result.success(data);
    }

    @PutMapping("/inventory/{id}/check")
    public Result<Inventory> checkInventory(
            @PathVariable Integer id,
            @Valid @RequestBody InventoryCheckRequest request) {
        Inventory data = inventoryService.checkInventory(id, request);
        return Result.success(data);
    }

    @GetMapping("/inventory/warnings")
    public Result<InventoryWarningListResponse> getInventoryWarnings() {
        InventoryWarningListResponse data = inventoryService.getInventoryWarnings();
        return Result.success(data);
    }

    @GetMapping("/inventory/stats")
    public Result<InventoryStatsResponse> getInventoryStats() {
        InventoryStatsResponse data = inventoryService.getInventoryStats();
        return Result.success(data);
    }
} 